<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;


/**
 * 后台首页控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class TongjiController extends AdminController {
    //业务统计
    public function index(){
		$ywlb   = D('Ywlb');
        $liebei = $ywlb->lb();
        $this->assign('liebei',$liebei);
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
			$lb          = I('leibie');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
            $this->assign('begin',$begin);
            $this->assign('end',$end);
			$this->assign('lb',$lb);
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
			$lb        = I('leibie');
			$this->assign('lb',$lb);
        }
        $zj_date       = get_date($begin,$end);
        foreach ($zj_date as $key => $value) {
            $data[$key]['time']          =  $value;
            $sj_date                =  strtotime($value);
            $data[$key]['jd']       =  $this->map($sj_date,$mm='jd',$lb);
            $data[$key]['qq']       =  $this->map($sj_date,$mm='qq',$lb);
            $data[$key]['phone']    =  $this->map($sj_date,$mm='phone',$lb);
            $data[$key]['yytime']   =  $this->map($sj_date,$mm='yytime',$lb);
			$data[$key]['jindtime'] =  $this->map($sj_date,$mm='jindtime',$lb);
			$data[$key]['wddtime']  =  $this->map($sj_date,$mm='wddtime',$lb);
            $data[$key]['lstime']   =  $this->map($sj_date,$mm='lstime',$lb);
			$data[$key]['xxlstime'] =  $this->map($sj_date,$mm='xxlstime',$lb);
            $data[$key]['xscj']     =  $this->map($sj_date,$mm='xscj',$lb);
            $data[$key]['xxcj']     =  $this->map($sj_date,$mm='xxcj',$lb);
            $data[$key]['zcj']      =  $data[$key]['xscj']+$data[$key]['xxcj'];
            $data[$key]['setmoney'] =  $this->money($sj_date,$ssss,$lb);
        }
        $this->assign('_list',$data);

        $index = 1; 
        while ($index<2) 
        { 
            $zj['jd']       =  $this->map1($begin,$end,$mm='jd',$lb);
            $zj['qq']       =  $this->map1($begin,$end,$mm='qq',$lb);
            $zj['phone']    =  $this->map1($begin,$end,$mm='phone',$lb);
            $zj['yytime']   =  $this->map1($begin,$end,$mm='yytime',$lb);
			$zj['jindtime'] =  $this->map1($begin,$end,$mm='jindtime',$lb);
			$zj['wddtime']  =  $this->map1($begin,$end,$mm='wddtime',$lb);
            $zj['lstime']   =  $this->map1($begin,$end,$mm='lstime',$lb);
            $zj['xxlstime'] =  $this->map1($begin,$end,$mm='xxlstime',$lb);
            $zj['xscj']     =  $this->map1($begin,$end,$mm='xscj',$lb);
            $zj['xxcj']     =  $this->map1($begin,$end,$mm='xxcj',$lb);
            $zj['zcj']      =  $zj['xscj']+$zj['xxcj'];
            $begin          =  strtotime($begin);
            $end            =  strtotime($end);
            $zj['setmoney'] =  $this->money($begin,$end,$lb);
            $index++; 

        } 

        $this->assign('zj',$zj);
        $this->meta_title = '业务统计';
        $this->display();
    }

    //渠道统计
    public function qudao(){
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
		/*  $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            } */
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
        $qudao   = D('Ywlb')->qd();
		$feiyong = D('Tuig');
        foreach ($qudao as $key => $value) {
            $data[$key]['name']     =  $value['name'];
            $data[$key]['jd']       =  $this->map1($begin,$end,$mm='jd',$cx='qudao',$value['uid']);
            $data[$key]['qq']       =  $this->map1($begin,$end,$mm='qq',$cx='qudao',$value['uid']);
            $data[$key]['phone']    =  $this->map1($begin,$end,$mm='phone',$cx='qudao',$value['uid']);
			$data[$key]['feiyong']  =  $feiyong->map($begin,$end,$value['uid']);
			$data[$key]['jindtime'] =  $this->map1($begin,$end,$mm='jindtime',$cx='qudao',$value['uid']);
			$data[$key]['wddtime']  =  $this->map1($begin,$end,$mm='wddtime',$cx='qudao',$value['uid']);
            $data[$key]['yytime']   =  $this->map1($begin,$end,$mm='yytime',$cx='qudao',$value['uid']);
            $data[$key]['lstime']   =  $this->map1($begin,$end,$mm='lstime',$cx='qudao',$value['uid']);
            $data[$key]['xscj']     =  $this->map1($begin,$end,$mm='xscj',$cx='qudao',$value['uid']);
            $data[$key]['xxcj']     =  $this->map1($begin,$end,$mm='xxcj',$cx='qudao',$value['uid']);
            $data[$key]['zcj']      =  $data[$key]['xscj']+$data[$key]['xxcj'];
            $data[$key]['setmoney'] =  $this->qdmoney($begin,$end,$cx='qudao',$value['uid']);
        }
		
		//微博+微博挖潜
			$data[5]['jd']          += $data[21]['jd'];
			$data[5]['qq']          += $data[21]['qq'];
			$data[5]['phone']       += $data[21]['phone'];
			$data[5]['feiyong']     += $data[21]['feiyong'];
			$data[5]['jindtime']    += $data[21]['jindtime'];
			$data[5]['wddtime']     += $data[21]['wddtime'];
			$data[5]['yytime']      += $data[21]['yytime'];
			$data[5]['lstime']      += $data[21]['lstime'];
			$data[5]['xscj']        += $data[21]['xscj'];
			$data[5]['xxcj']        += $data[21]['xxcj'];
			$data[5]['zcj']         += $data[21]['zcj'];
			$data[5]['setmoney']    += $data[21]['setmoney'];
		//微信+微信挖潜
			$data[6]['jd']          += $data[22]['jd'];
			$data[6]['qq']          += $data[22]['qq'];
			$data[6]['phone']       += $data[22]['phone'];
			$data[6]['feiyong']     += $data[22]['feiyong'];
			$data[6]['jindtime']    += $data[22]['jindtime'];
			$data[6]['wddtime']     += $data[22]['wddtime'];
			$data[6]['yytime']      += $data[22]['yytime'];
			$data[6]['lstime']      += $data[22]['lstime'];
			$data[6]['xscj']        += $data[22]['xscj'];
			$data[6]['xxcj']        += $data[22]['xxcj'];
			$data[6]['zcj']         += $data[22]['zcj'];
			$data[6]['setmoney']    += $data[22]['setmoney'];		
		//点评+点评挖潜
			$data[13]['jd']          += $data[23]['jd'];
			$data[13]['qq']          += $data[23]['qq'];
			$data[13]['phone']       += $data[23]['phone'];
			$data[13]['feiyong']     += $data[23]['feiyong'];
			$data[13]['jindtime']    += $data[23]['jindtime'];
			$data[13]['wddtime']     += $data[23]['wddtime'];
			$data[13]['yytime']      += $data[23]['yytime'];
			$data[13]['lstime']      += $data[23]['lstime'];
			$data[13]['xscj']        += $data[23]['xscj'];
			$data[13]['xxcj']        += $data[23]['xxcj'];
			$data[13]['zcj']         += $data[23]['zcj'];
			$data[13]['setmoney']    += $data[23]['setmoney'];	
		//删除挖潜数据（微博、微信、点评）
		unset($data[23]);
		unset($data[22]);
		unset($data[21]);
		
		//排序，根据建单排序
		foreach ($data as $key => $row){
			$volume[$key]  = $row['jd'];
		}
		//排序，根据建单排序 SORT_DESC倒序
		array_multisort($volume, SORT_DESC, $data);

        $this->assign('_list',$data);   

        $index = 1; 
        while ($index<2) 
        { 	
            $zj['jd']       =  $this->map1($begin,$end,$mm='jd');
            $zj['qq']       =  $this->map1($begin,$end,$mm='qq');
            $zj['phone']    =  $this->map1($begin,$end,$mm='phone');
			$zj['feiyong']  =  $feiyong->map($begin,$end,999);//查询总计 "999"
            $zj['yytime']   =  $this->map1($begin,$end,$mm='yytime');
			$zj['jindtime'] =  $this->map1($begin,$end,$mm='jindtime');
			$zj['wddtime']  =  $this->map1($begin,$end,$mm='wddtime');
            $zj['lstime']   =  $this->map1($begin,$end,$mm='lstime');
            $zj['xscj']     =  $this->map1($begin,$end,$mm='xscj');
            $zj['xxcj']     =  $this->map1($begin,$end,$mm='xxcj');
			$zj['xxcj']     =  $this->map1($begin,$end,$mm='xxcj');
            $zj['zcj']      =  $zj['xscj']+$zj['xxcj'];
            $zj['setmoney'] =  $this->qdmoney($begin,$end);
            $index++; 

        } 

        $this->assign('zj',$zj);

        $this->meta_title = '渠道统计';
        $this->display();
    }
	
	    //成本统计
    public function chengben(){
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
		/*  $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            } */
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
        $qudao   = D('Ywlb')->qd();
		$feiyong = D('Tuig');
        foreach ($qudao as $key => $value) {
            $data[$key]['name']     =  $value['name'];
            $data[$key]['jd']       =  $this->map1($begin,$end,$mm='jd',$cx='qudao',$value['uid']);
            $data[$key]['qq']       =  $this->map1($begin,$end,$mm='qq',$cx='qudao',$value['uid']);
            $data[$key]['phone']    =  $this->map1($begin,$end,$mm='phone',$cx='qudao',$value['uid']);
			$data[$key]['feiyong']  =  $feiyong->map($begin,$end,$value['uid']);
			$data[$key]['jindtime'] =  $this->map1($begin,$end,$mm='jindtime',$cx='qudao',$value['uid']);
			$data[$key]['wddtime']  =  $this->map1($begin,$end,$mm='wddtime',$cx='qudao',$value['uid']);
            $data[$key]['yytime']   =  $this->map1($begin,$end,$mm='yytime',$cx='qudao',$value['uid']);
            $data[$key]['lstime']   =  $this->map1($begin,$end,$mm='lstime',$cx='qudao',$value['uid']);
            $data[$key]['xscj']     =  $this->map1($begin,$end,$mm='xscj',$cx='qudao',$value['uid']);
            $data[$key]['xxcj']     =  $this->map1($begin,$end,$mm='xxcj',$cx='qudao',$value['uid']);
            $data[$key]['zcj']      =  $data[$key]['xscj']+$data[$key]['xxcj'];
            $data[$key]['setmoney'] =  $this->qdmoney($begin,$end,$cx='qudao',$value['uid']);
        }
		
		//微博+微博挖潜
			$data[5]['jd']          += $data[21]['jd'];
			$data[5]['qq']          += $data[21]['qq'];
			$data[5]['phone']       += $data[21]['phone'];
			$data[5]['feiyong']     += $data[21]['feiyong'];
			$data[5]['jindtime']    += $data[21]['jindtime'];
			$data[5]['wddtime']     += $data[21]['wddtime'];
			$data[5]['yytime']      += $data[21]['yytime'];
			$data[5]['lstime']      += $data[21]['lstime'];
			$data[5]['xscj']        += $data[21]['xscj'];
			$data[5]['xxcj']        += $data[21]['xxcj'];
			$data[5]['zcj']         += $data[21]['zcj'];
			$data[5]['setmoney']    += $data[21]['setmoney'];
		//微信+微信挖潜
			$data[6]['jd']          += $data[22]['jd'];
			$data[6]['qq']          += $data[22]['qq'];
			$data[6]['phone']       += $data[22]['phone'];
			$data[6]['feiyong']     += $data[22]['feiyong'];
			$data[6]['jindtime']    += $data[22]['jindtime'];
			$data[6]['wddtime']     += $data[22]['wddtime'];
			$data[6]['yytime']      += $data[22]['yytime'];
			$data[6]['lstime']      += $data[22]['lstime'];
			$data[6]['xscj']        += $data[22]['xscj'];
			$data[6]['xxcj']        += $data[22]['xxcj'];
			$data[6]['zcj']         += $data[22]['zcj'];
			$data[6]['setmoney']    += $data[22]['setmoney'];		
		//点评+点评挖潜
			$data[13]['jd']          += $data[23]['jd'];
			$data[13]['qq']          += $data[23]['qq'];
			$data[13]['phone']       += $data[23]['phone'];
			$data[13]['feiyong']     += $data[23]['feiyong'];
			$data[13]['jindtime']    += $data[23]['jindtime'];
			$data[13]['wddtime']     += $data[23]['wddtime'];
			$data[13]['yytime']      += $data[23]['yytime'];
			$data[13]['lstime']      += $data[23]['lstime'];
			$data[13]['xscj']        += $data[23]['xscj'];
			$data[13]['xxcj']        += $data[23]['xxcj'];
			$data[13]['zcj']         += $data[23]['zcj'];
			$data[13]['setmoney']    += $data[23]['setmoney'];	
		//删除挖潜数据（微博、微信、点评）
		unset($data[23]);
		unset($data[22]);
		unset($data[21]);
		
		//排序，根据建单排序
		foreach ($data as $key => $row){
			$volume[$key]  = $row['jd'];
		}
		//排序，根据建单排序 SORT_DESC倒序
		array_multisort($volume, SORT_DESC, $data);

        $this->assign('_list',$data);   

        $index = 1; 
        while ($index<2) 
        { 	
            $zj['jd']       =  $this->map1($begin,$end,$mm='jd');
            $zj['qq']       =  $this->map1($begin,$end,$mm='qq');
            $zj['phone']    =  $this->map1($begin,$end,$mm='phone');
			$zj['feiyong']  =  $feiyong->map($begin,$end,999);//查询总计 "999"
            $zj['yytime']   =  $this->map1($begin,$end,$mm='yytime');
			$zj['jindtime'] =  $this->map1($begin,$end,$mm='jindtime');
			$zj['wddtime']  =  $this->map1($begin,$end,$mm='wddtime');
            $zj['lstime']   =  $this->map1($begin,$end,$mm='lstime');
            $zj['xscj']     =  $this->map1($begin,$end,$mm='xscj');
            $zj['xxcj']     =  $this->map1($begin,$end,$mm='xxcj');
			$zj['xxcj']     =  $this->map1($begin,$end,$mm='xxcj');
            $zj['zcj']      =  $zj['xscj']+$zj['xxcj'];
            $zj['setmoney'] =  $this->qdmoney($begin,$end);
            $index++; 

        } 

        $this->assign('zj',$zj);

        $this->meta_title = '渠道统计';
        $this->display();
    }
	
	
	
    //线上门市统计
    public function kefu(){
        $xianshang = xianshang();
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
        foreach ($xianshang as $key => $value) {
            $data[$key]['name']     =  $value['nickname'];
            $data[$key]['jd']       =  $this->map1($begin,$end,$mm='jd',$cx='xsjd',$value['uid']);
            $data[$key]['qq']       =  $this->map1($begin,$end,$mm='qq',$cx='xsjd',$value['uid']);
            $data[$key]['phone']    =  $this->map1($begin,$end,$mm='phone',$cx='xsjd',$value['uid']);
            $data[$key]['yytime']   =  $this->map1($begin,$end,$mm='yytime',$cx='xsjd',$value['uid']);
			$data[$key]['jindtime'] =  $this->map1($begin,$end,$mm='jindtime',$cx='xsjd',$value['uid']);
			$data[$key]['wddtime']  =  $this->map1($begin,$end,$mm='wddtime',$cx='xsjd',$value['uid']);
            $data[$key]['lstime']   =  $this->map1($begin,$end,$mm='lstime',$cx='xsjd',$value['uid']);
            $data[$key]['xscj']     =  $this->map1($begin,$end,$mm='xscj',$cx='xsjd',$value['uid']);
            $data[$key]['xxcj']     =  $this->map1($begin,$end,$mm='xxcj',$cx='xsjd',$value['uid']);
            $data[$key]['zcj']      =  $data[$key]['xscj']+$data[$key]['xxcj'];
            $data[$key]['setmoney'] =  $this->qdmoney($begin,$end,$cx='xsjd',$value['uid']);
        }
		foreach ($data as $key => $value) {
			$zj['jd']       += $value['jd'];
			$zj['qq']       += $value['qq'];
			$zj['phone']    += $value['phone'];
			$zj['yytime']   += $value['yytime'];
			$zj['jindtime'] += $value['jindtime'];
			$zj['wddtime']  += $value['wddtime'];
			$zj['lstime']   += $value['lstime'];
			$zj['xscj']     += $value['xscj'];
			$zj['xxcj']     += $value['xxcj'];
			$zj['zcj']      += $value['zcj'];
			$zj['setmoney'] += $value['setmoney'];
		}
		$this->assign('zj',$zj);
        $this->assign('_list',$data);   



        $this->meta_title = '线上门市统计';
        $this->display();
    }
	//线下门市统计
    public function menshi(){
        $xianxia = xianxia();
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
        foreach ($xianxia as $key => $value) {
            $data[$key]['name']     =  $value['nickname'];
            $data[$key]['jd']       =  $this->map1($begin,$end,$mm='jd',$cx='xxjd',$value['uid']);
            $data[$key]['qq']       =  $this->map1($begin,$end,$mm='qq',$cx='xxjd',$value['uid']);
            $data[$key]['phone']    =  $this->map1($begin,$end,$mm='phone',$cx='xxjd',$value['uid']);
            $data[$key]['yytime']   =  $this->map1($begin,$end,$mm='yytime',$cx='xxjd',$value['uid']);
			$data[$key]['jindtime'] =  $this->map1($begin,$end,$mm='jindtime',$cx='xxjd',$value['uid']);
			$data[$key]['wddtime']  =  $this->map1($begin,$end,$mm='wddtime',$cx='xxjd',$value['uid']);
            $data[$key]['lstime']   =  $this->map1($begin,$end,$mm='lstime',$cx='xxjd',$value['uid']);
            $data[$key]['xscj']     =  $this->map1($begin,$end,$mm='xscj',$cx='xxjd',$value['uid']);
            $data[$key]['xxcj']     =  $this->map1($begin,$end,$mm='xxcj',$cx='xxjd',$value['uid']);
            $data[$key]['zcj']      =  $data[$key]['xscj']+$data[$key]['xxcj'];
            $data[$key]['setmoney'] =  $this->qdmoney($begin,$end,$cx='xxjd',$value['uid']);
        }
		foreach ($data as $key => $value) {
			$zj['jd']       += $value['jd'];
			$zj['qq']       += $value['qq'];
			$zj['phone']    += $value['phone'];
			$zj['yytime']   += $value['yytime'];
			$zj['jindtime'] += $value['jindtime'];
			$zj['wddtime']  += $value['wddtime'];
			$zj['lstime']   += $value['lstime'];
			$zj['xscj']     += $value['xscj'];
			$zj['xxcj']     += $value['xxcj'];
			$zj['zcj']      += $value['zcj'];
			$zj['setmoney'] += $value['setmoney'];
		}
		$this->assign('zj',$zj);
        $this->assign('_list',$data);   



        $this->meta_title = '线下门市统计';
        $this->display();
    }
	//客服统计
    public function caiwu(){
        $kefu = kefu();
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
			$value       = I('kf');
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
			$value     = $kefu['0']['uid'];//获取第一客服UID
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
		$zj_date  = get_date($begin,$end);
		foreach($zj_date as $key => $r){
			$data[$key]['time']   = $r;
			$begin   = $r.' 00:00:01';
			$end     = $r.' 23:59:59';
			$data[$key]['jd']       =  $this->map2($begin,$end,$mm='jd',$cx='kefu',$value);
			$data[$key]['qq']       =  $this->map2($begin,$end,$mm='qq',$cx='kefu',$value);
			$data[$key]['phone']    =  $this->map2($begin,$end,$mm='phone',$cx='kefu',$value);
			$zj['jd']               += $data[$key]['jd'];
			$zj['qq']               += $data[$key]['qq'];
			$zj['phone']            += $data[$key]['phone'];
			$zbegin   = $r.' 00:00:01';
			$zend     = $r.' 20:59:59';
			$data[$key]['zjd']       =  $this->map2($zbegin,$zend,$mm='jd',$cx='kefu',$value);
			$data[$key]['zqq']       =  $this->map2($zbegin,$zend,$mm='qq',$cx='kefu',$value);
			$data[$key]['zphone']    =  $this->map2($zbegin,$zend,$mm='phone',$cx='kefu',$value);
			$zj['zjd']               += $data[$key]['zjd'];
			$zj['zqq']               += $data[$key]['zqq'];
			$zj['zphone']            += $data[$key]['zphone'];
			$wbegin   = $r.' 21:00:00';
			$wend     = $r.' 23:59:59';
			$data[$key]['wjd']       =  $this->map2($wbegin,$wend,$mm='jd',$cx='kefu',$value);
			$data[$key]['wqq']       =  $this->map2($wbegin,$wend,$mm='qq',$cx='kefu',$value);
			$data[$key]['wphone']    =  $this->map2($wbegin,$wend,$mm='phone',$cx='kefu',$value);
			$zj['wjd']               += $data[$key]['wjd'];
			$zj['wqq']               += $data[$key]['wqq'];
			$zj['wphone']            += $data[$key]['wphone'];
		}
		$this->assign('zj',$zj);
		$this->assign('kf',$value);
		$this->assign('kefu',$kefu);
        $this->assign('_list',$data);   



        $this->meta_title = '财务核算统计';
        $this->display();
    }
	//策划统计
    public function cehua(){
        $kefu  = kefu();
		$ywlb   = D('Ywlb');
		$qudao  = $ywlb->qd();
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
			$value       = I('kf');
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
			$value     = "88888";//获取第一客服UID
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
		$end     = $end.' 23:59:59';
		foreach($qudao as $key => $r){
			$data[$key]['name']       =  $r['name'];
			$data[$key]['jd']       =  $this->map2($begin,$end,$mm='jd',$cx='kefu',$value,$qd='qudao',$r['uid']);
			$data[$key]['qq']       =  $this->map2($begin,$end,$mm='qq',$cx='kefu',$value,$qd='qudao',$r['uid']);
			$data[$key]['phone']    =  $this->map2($begin,$end,$mm='phone',$cx='kefu',$value,$qd='qudao',$r['uid']);
			$zj['jd']               += $data[$key]['jd'];
			$zj['qq']               += $data[$key]['qq'];
			$zj['phone']            += $data[$key]['phone'];
		}
		//排序，根据建单排序
		foreach ($data as $key => $row){
			$volume[$key]  = $row['jd'];
		}
		//排序，根据建单排序 SORT_DESC倒序
		array_multisort($volume, SORT_DESC, $data);
		
		$this->assign('zj',$zj);
		$this->assign('kf',$value);
		$this->assign('kefu',$kefu);
        $this->assign('_list',$data);   



        $this->meta_title = '策划统计';
        $this->display();
    }
		//客服统计
    public function qihua(){
        $kefu = kefu();
        if(I('time_start') && I('time_end')){
            $begin       = I('time_start');
            $end         = I('time_end');
            $pdkssj      = strtotime($begin)+31*24*3600; 
            $pdjssj      = strtotime($end);
			$value       = I('kf');
            if($pdjssj >= $pdkssj){
                $this->error('只能查询一个月区间的数据！！');
            }
        }else{
            $shijian   = time()-30*24*3600; //减30天
            $begin     = date('Y-m-d',$shijian);  //当前时间
            $end       = date('Y-m-d',time()); //减30天转换
			$value     = $kefu['0']['uid'];//获取第一客服UID
        }
        $this->assign('begin',$begin);
        $this->assign('end',$end);
		$zj_date  = get_date($begin,$end);
		foreach($zj_date as $key => $r){
			$data[$key]['time']   = $r;
			$begin   = $r.' 00:00:01';
			$end     = $r.' 23:59:59';
			$data[$key]['jd']       =  $this->map2($begin,$end,$mm='jd',$cx='kefu',$value);
			$data[$key]['qq']       =  $this->map2($begin,$end,$mm='qq',$cx='kefu',$value);
			$data[$key]['phone']    =  $this->map2($begin,$end,$mm='phone',$cx='kefu',$value);
			$zj['jd']               += $data[$key]['jd'];
			$zj['qq']               += $data[$key]['qq'];
			$zj['phone']            += $data[$key]['phone'];
			
		}
		$this->assign('zj',$zj);
		$this->assign('kf',$value);
		$this->assign('kefu',$kefu);
        $this->assign('_list',$data);   



        $this->meta_title = '邀约客服统计';
        $this->display();
    }


    //查询单日
    public function map($sj_date,$mm,$yw=null){
            $map['puth']     = array('eq','1');
			//判断业务类别
			switch ($yw){
				case 31:
				  $map['lb']   = array('eq','31');
				  break;  
				case 113:
				  $map['lb']   = array('eq','113');
				  break;
				case 114:
				  $map['lb']   = array('eq','114');
				  break;
				case 123:
				  $map['lb']   = array('eq','123');
				  break;
				case 124:
				  $map['lb']   = array('eq','124');
				  break;   
				case 125:
				  $map['lb']   = array('eq','125');
				  break;
				case 126:
				  $map['lb']   = array('eq','126');
				  break;
				case 139:
				  $map['lb']   = array('eq','139');
				  break;
				case 175:
				  $map['lb']   = array('eq','175');
				  break;  	  
				}
            if($mm == 'jd'){
				$map['ywstate']   = array('not in','66');
                $map['jdtime']   = array('between',array($sj_date,$sj_date+86399));
            }
            if($mm == 'qq'){
                $map['qq']       = array('gt','0');
				$map['ywstate']   = array('not in','66');
                $map['jdtime']   = array('between',array($sj_date,$sj_date+86399));
            }
            if($mm == 'phone'){
				$map['ywstate']   = array('not in','66');
                $map['phone']       = array('gt','0');
                $map['jdtime']   = array('between',array($sj_date,$sj_date+86399));
            }
            if($mm == 'yytime'){
				$map['ywstate']   = array('not in','66');
                $map['yytime']   = array('between',array($sj_date,$sj_date+86399));    
            }
			if($mm == 'jindtime'){
				$map['ywstate']   = array('not in','66');
                $map['jindtime']   = array('between',array($sj_date,$sj_date+86399));    
            }
			if($mm == 'wddtime'){
				$map['ywstate']   = array('not in','66');
                $map['wddtime']   = array('between',array($sj_date,$sj_date+86399));    
            }
            if($mm == 'lstime'){
				$map['ywstate']   = array('not in','66');
                $map['lstime']   = array('between',array($sj_date,$sj_date+86399));
            }
			if($mm == 'xxlstime'){
				$map['ywstate']       = array('eq','149');	
                $map['lstime']   = array('between',array($sj_date,$sj_date+86399));
            }
            if($mm == 'xscj'){
                $map['ywstate']       = array('eq','67');
                $map['ddtime']   = array('between',array($sj_date,$sj_date+86399));
            }
            if($mm == 'xxcj'){
                $map['ywstate']       = array('in','115,151');
                $map['ddtime']   = array('between',array($sj_date,$sj_date+86399));
            }
            $data   = D('Yewu')->where($map)->count();
            return $data;

    }
    //查询总计
    public function map1($begin,$end,$mm,$cx,$uid){
            $begin = strtotime($begin);
            $end   = strtotime($end);
            $map['puth']         =  array('eq','1');
			$map['ywstate']   = array('not in','66');
			switch ($cx){
				case 31:
				  $map['lb']   = array('eq','31');
				  break;  
				case 113:
				  $map['lb']   = array('eq','113');
				  break;
				case 114:
				  $map['lb']   = array('eq','114');
				  break;
				case 123:
				  $map['lb']   = array('eq','123');
				  break;
				case 124:
				  $map['lb']   = array('eq','124');
				  break;   
				case 125:
				  $map['lb']   = array('eq','125');
				  break;
				case 126:
				  $map['lb']   = array('eq','126');
				  break;
				case 139:
				  $map['lb']   = array('eq','139');
				  break;  
				case 175:
				  $map['lb']   = array('eq','175');
				  break;  
				default:
				}
            if($cx == 'qudao'){
                $map['qd']       =  array('eq',$uid);
            }
            if($cx == 'xsjd'){
                $map['xsjd']       =  array('eq',$uid);
            }
			if($cx == 'xxjd'){
                $map['xxjd']       =  array('eq',$uid);
            }
			if($cx == 'kefu'){
				$map['kf']         =  array('eq',$uid);
			}
            if($mm == 'jd'){
                $map['jdtime']   = array('between',array($begin,$end+86399));
            }
            if($mm == 'qq'){
                $map['qq']       = array('gt','0');
                $map['jdtime']   = array('between',array($begin,$end+86399));
            }
            if($mm == 'phone'){
                $map['phone']       = array('gt','0');
                $map['jdtime']   = array('between',array($begin,$end+86399));
            }
            if($mm == 'yytime'){
                $map['yytime']   = array('between',array($begin,$end+86399));    
            }
			if($mm == 'jindtime'){
                $map['jindtime']   = array('between',array($begin,$end+86399));    
            }
			if($mm == 'wddtime'){
                $map['wddtime']   = array('between',array($begin,$end+86399));    
            }
            if($mm == 'lstime'){
                $map['lstime']   = array('between',array($begin,$end+86399));
            }
			if($mm == 'xxlstime'){
				$map['ywstate']       = array('eq','149');
                $map['lstime']   = array('between',array($begin,$end+86399));
            }
            if($mm == 'xscj'){
                $map['ywstate']       = array('eq','67');
                $map['ddtime']   = array('between',array($begin,$end+86399));
            }
            if($mm == 'xxcj'){
                $map['ywstate']       = array('in','115,151');
                $map['ddtime']   = array('between',array($begin,$end+86399));
            }
            $data   = D('Yewu')->where($map)->count();
            return $data;

    }
	//统计邀约数据，财务使用
    public function map2($begin,$end,$mm,$cx,$uid,$qd = null,$qdid = null){
            $begin = strtotime($begin);
            $end   = strtotime($end);
            $map['puth']         =  array('eq','1');
			$map['ywstate']      = array('not in','66');
            if($cx == 'qudao'){
                $map['qd']       =  array('eq',$uid);
            }
            if($cx == 'xsjd'){
                $map['xsjd']       =  array('eq',$uid);
            }
			if($cx == 'kefu'){
				if($uid == '88888'){
					$map['kf']         =  array('gt','1');
				}else{
					$map['kf']         =  array('eq',$uid);
				}
			}
			if($qd == 'qudao'){
                $map['qd']       =  array('eq',$qdid);
            }
            if($mm == 'jd'){
                $map['jdtime']   = array('between',array($begin,$end));
            }
            if($mm == 'qq'){
                $map['qq']       = array('neq','');
                $map['jdtime']   = array('between',array($begin,$end));
            }
            if($mm == 'phone'){
                $map['phone']    = array('neq','');
                $map['jdtime']   = array('between',array($begin,$end));
            }
            if($mm == 'yytime'){
                $map['yytime']   = array('between',array($begin,$end));    
            }

            if($mm == 'lstime'){
                $map['lstime']   = array('between',array($begin,$end));
            }
            if($mm == 'xscj'){
                $map['ywstate']       = array('eq','67');
                $map['ddtime']   = array('between',array($begin,$end));
            }
            if($mm == 'xxcj'){
				$map['ywstate']       = array('in','115,151');
                $map['ddtime']   = array('between',array($begin,$end));
            }
            $data   = M('Yewu')->where($map)->count();

            return $data;

    }
	
    //金钱
    public function money($sj_date,$end,$yw=null){
		//判断业务类别
			switch ($yw){
				case 31:
				  $map['lb']   = array('eq','31');
				  break;  
				case 113:
				  $map['lb']   = array('eq','113');
				  break;
				case 114:
				  $map['lb']   = array('eq','114');
				  break;
				case 123:
				  $map['lb']   = array('eq','123');
				  break;
				case 124:
				  $map['lb']   = array('eq','124');
				  break;  
				case 125:
				  $map['lb']   = array('eq','125');
				  break;
				case 126:
				  $map['lb']   = array('eq','126');
				  break;
				case 139:
				  $map['lb']   = array('eq','139');
				  break;
				case 175:
				  $map['lb']   = array('eq','175');
				  break;  
				default:

				}
        if($end){
            $map['ddtime']   = array('between',array($sj_date,$end+86399));
        }else{
            $map['ddtime']   = array('between',array($sj_date,$sj_date+86399));
        }
       
        $data   =  D('Yewu')->where($map)->sum('setmoney');       
        return $data;
    }

    public function qdmoney($begin,$end,$cx,$uid){
        $begin = strtotime($begin);
        $end   = strtotime($end);
        if($cx == 'qudao'){
            $map['qd']       =  array('eq',$uid);
        }
        if($cx == 'xsjd'){
            $map['xsjd']       =  array('eq',$uid);
        }
		if($cx == 'xxjd'){
            $map['xxjd']       =  array('eq',$uid);
        }
        $map['ddtime']   = array('between',array($begin,$end+86399));       
        $data   =  D('Yewu')->where($map)->sum('setmoney');       
        return $data;
    }


}
